Client Side Template

{*root}{/*root}

Description

Allows you to use headers and footers when the JSON data being passed in is an array.

Before the root command was created, when data was passed into the A5.u.template.expand() function as an array (not an object with an array as property of the object), you could not use the {*header} and {*footer} directives in your template. It was therefore not possible to generate a headers or footers for the array data. In order to achieve these features it was necessary to artificially structure data as a top level object with an array as a property of the object. The {*root} tag eliminates the need to do any of this when the data that is passed in is an array. Consider the following sample data:

[
    {firstname: 'Fred', lastname: 'Smith'},
    {firstname: 'John', lastname: 'Jones'}
]

and the following template:

{*root}
{*header}There are {root.length} people<br />{/*header}
{firstname} {lastname}<br />
{*footer}Count: {root.length} {/*footer}
{/*root}

The result would look like this:

There are 2 people
Fred Smith
John Jones
Count: 2
Try removing the root command from the template and the header and footer will disappear from the HTML output.

How the root command works

The root command effectively does this to the JSON data:

{
    root: [
            {firstname: 'Fred', lastname: 'Smith'},
            {firstname: 'John', lastname: 'Jones'}
           ]
    }